package rabbit.direct;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author honway.liu
 * @date 2019-05-29 21:08
 * @email gm100861@gmail.com
 * @blog http://linuxsogood.org
 */
public class Producer4DirectExchange {
    public static void main(String[] args) throws IOException, TimeoutException {
        // 1. 创建ConnectionFactory
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("127.0.0.1");
        connectionFactory.setPort(5672);
        connectionFactory.setVirtualHost("/");

        // 2. 通过工厂类获取连接
        Connection connection = connectionFactory.newConnection();

        // 3. 使用connection创建channel
        Channel channel = connection.createChannel();

        String exchange = "test_direct_exchange";
        String routingKey = "test.direct";
        String msg = "Hello, rabbitMQ, This is test msg.";

        channel.basicPublish(exchange, routingKey, null, msg.getBytes());

    }
}
